<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
</head>
<body>
    <button id="btn">发送请求</button>
</body>
<script>
    //如果axios请求失败，返回一个失败的promise ，值为一个对象，对象中包含错误信息
  /* o{code: "ECONNABORTED"
    config: {transitional: {…}, transformRequest: Array(1), transformResponse: Array(1), timeout: 1, adapter: ƒ, …}
    message: "timeout of 1ms exceeded"
    name: "AxiosError"
    request: XMLHttpRequest {onreadystatechange: null, readyState: 4, timeout: 1, withCredentials: false, upload: XMLHttpRequestUpload, …}}*/


    const btn = document.getElementById('btn')
    const  re = axios({
                     //axios请求接收一个配置对象,下面是常用的,只有url是必须写的
                    url:'/user',//路径
                    method:'get',//请求类型
                    headers:{//是即将被发送的自定义请求头

                    },
                    params:{//是即将与请求一起发送的 URL 参数，必须是一个对象
                        userId:'001'
                    },
                    data:{},//是作为请求主体被发送的数据，只适用于post和put
                    timeout:1,//指定请求超时的毫秒数(0 表示无超时时间)
                })
    console.log(re)
</script>
</html>